//
//  RouteManager.swift
//  CosClub_Basis
//
//  Created by iOS on 2020/5/18.
//  Copyright © 2020 iOS. All rights reserved.
//
import URLNavigator
import Foundation

public protocol RoutePath {
    func regist() -> String
    func push() -> String
}




public class RouteManager {
    
    public static let shared = Navigator()
    public static func regist(pattern: RoutePath, viewController: UIViewController) {
        
        Self.shared.register(pattern.regist()) { (url, parameter, context) -> UIViewController? in
            if let context = context as? Dictionary<String, Any?> {
                viewController.setValuesForKeys(context as [String : Any])
            }
            
            return viewController
        }
    }
    
    public static func push(url: RoutePath, context: Any?) {
        Self.shared.push(url.push(), context: context, from: nil, animated: true)
    }
    
    public static func presen(url: RoutePath, context: Any?) {
        Self.shared.presentURL(url.push(), context: context, from: nil, animated: true)
    }
}
